<template>
	<view>
        <view class="logo">
			<view class="img">
				<image :src="logo" mode="widthFix"></image>
			</view>
		</view>
		<view class="form re">
<!-- 			<view class="username">
				<view class="get-code" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">{{getCodeText}}</view>
				<input placeholder="请输入手机号" v-model="mobile"  placeholder-style="color: #ccc;"/>
			</view>
			<view class="code">
				<input placeholder="请输入验证码" v-model="code" placeholder-style="color: #ccc;"/>
			</view> -->
			<view class="code">
				<input placeholder="请输入邀请码" v-model="invite_code" placeholder-style="color: #ccc;"/>
			</view>
			<!--#ifdef MP-WEIXIN -->
			<button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>
			<!--#endif -->
		</view>
		
	</view>
</template>

<script>
	import { checkPhone, isEmpty,isEmptyObj } from '../../utils';
	import { mapState,mapMutations} from 'vuex';
	export default {
		data() {
			return {
				invite_code:'',
				session_key:'',
			}
		},
		computed: {
			...mapState('user',['token','wxMiniOpenId','openid']),
			...mapState('sys', ['logo']),
		},
		onLoad() {
			// this.getLogo();
			// #ifdef MP-WEIXIN
			this.xcxlogin();
			// #endif
		},
		onBackPress() {
			return uni.switchTab({
				url:'/pages/user/user'
			})
		},
		methods: {
			...mapMutations('user',['setWxMiniOpenId','setOpenId']),
			...mapMutations('sys',['setLogo']),
			getLogo(){
				if(isEmpty(this.logo)){
					this.$ajax.get('common/logo').then(data=>{
						this.setLogo(data);
					})
				}
			},
			// #ifdef MP-WEIXIN
			xcxlogin(e) {  
				let that=this;
				uni.login({  
					success: (res) => {  
						that.$ajax.get('wechat/getxcxopenidnotoken',{code:res.code}).then(data=>{
							if(data.session_key){
								this.session_key = data.session_key;
							}else{
								this.$api.msg('授权失败');
							}
							
						})
					}  
				})  
			},  
			getPhoneNumber(e) {
			　　if(e.detail.errMsg=="getPhoneNumber:ok"){
					let param={
						iv:e.detail.iv,
						encryptedData: e.detail.encryptedData,
						session_key:this.session_key,
						openid:this.wxMiniOpenId,
						invite_code:this.invite_code
					}
					this.$ajax.get('wechat/decodephone',param).then(data=>{
						console.log(data);
						if(0==data.error){
							this.$api.msg('绑定成功');
							setTimeout(function(){
								return uni.switchTab({
									url:'/pages/user/user'
								})
							},500)
						}
					})
			        
			    }else{
			        console.log('用户点击了拒绝') ;  
			    }
			},
			// #endif
		}
	}
</script>

<style lang="scss">
	page {
		background: #FFFFFF;
		height: 100%;
	}
	.icon {
			color:#ffffff;
		}
	.logo {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		.img {
			width: 200rpx;
			height: 200rpx;
			margin: 50rpx 0;
			image {
				width: 100%;
				height: 100%;
				border-radius: 100%;
				border: 1px solid $base-color;
			}
		}
	}
	.form {
		width: 100%;
		padding: 0 7%;
		font-size: 30upx;
		.password,
		.code {
			width: 100%;
			height: 80upx;
			display: flex;
			align-items: center;
			border-radius: 45upx;
			background-color: #FFFFFF;
			border: 1px solid $base-color;
			padding: 0 45upx;
			box-sizing: border-box;
			margin-bottom: 26upx;
			
			input {
				width: 100%;
				height: 50upx;
				color: $font-color-000;
				font-weight: 200;
				font-size: $font-lg;
			}
		}
		.btn {
			color: #FFFFFF;
			width: 100%;
			height: 90upx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 30upx;
			background-color: $nav-bg;
			font-size: $font-lg;
		}
	}

	
</style>
